package com.lamda.zhekou.manager;

import com.lamda.zhekou.exception.ZheKouException;
import com.lamda.zhekou.model.*;
import com.lamda.zhekou.vo.HostVo;
import com.lamda.zhekou.vo.IncomeTotalVo;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;

/**
 * Created by MJiao on 15/8/16.
 */
public interface ServerHostManager {

    /**
     * 注册主机到Master
     *
     * @param serverHost
     * @throws ZheKouException
     */
    void registerServerHost(ServerHost serverHost) throws ZheKouException;

    /**
     * 添加VPS
     *
     * @param serverHostId
     * @param name
     * @param status
     */
    void addVPS(Long serverHostId, String name, String status);


    PageModel<ServerHost> pagingServerHost();


    PageModel<User> paging(int pageNo, int pageSize, boolean asc);

    List<HostVo> getHostsByFilter(String keyWord);


    ServerHost fgetServerHostByIp(String ip);

    void update(ServerHost serverHost);

    /**
     * 分配vps给用户
     *
     * @param operator
     * @param userEmail
     * @param host
     * @param vpsId
     * @param expireTime
     * @param rmb
     * @throws ZheKouException
     */
    void registerVps(Long operator, String userEmail, Long host, Long vpsId, Timestamp expireTime,int type, float rmb) throws ZheKouException;

    List<ServerHost> getAllServerHosts();

    ServerHost getServerHostById(Long serverHostId);

    /**
     * 查询主机的购买情况
     *
     * @param serverHostId
     * @return
     */
    List<UserVps> getUserVpsListBy(Set<VPS> serverHostId);

    /**
     * 查询用户所拥有的vps
     *
     * @param userId
     * @return
     */
    List<UserVps> findUserVpsListByUserId(Long userId);

    List<VpsBuyRecord> getAllVpsBuyRecordList();

    List<IncomeTotalVo> getIncomeTotalList();

    VPS getVpsByVpsId(Long vpsId);

    void checkWarning();

    void checkExpired();//查询过期机器


    UserVps getUserVpsByUVId(Long userVpsId);

    /**
     * 续费
     *
     * @param operatorUserId
     * @param userVpsId
     * @param expireTime
     * @param rmb
     * @throws ZheKouException
     */
    void renewVps(Long operatorUserId, Long userVpsId, Timestamp expireTime, float rmb) throws ZheKouException;

    /**
     * 暂停用户的vps
     *
     * @param operatorUserId
     * @param userVpsId
     */
    void disableUserVps(Long operatorUserId, Long userVpsId) throws ZheKouException;

    /**
     * 初始化vps(将已经过期的VPS)
     * @param operatorUserId
     * @param userVpsId
     */
    void doInitVPS(Long operatorUserId, Long userVpsId) throws ZheKouException;
    /**
     * 查询指定时间范围内的购买记录
     *
     *
     * @param hostId
     * @param startTimestamp
     * @param endTimestamp
     * @return
     */
    List<VpsBuyRecord> findVpsBuyRecords(Long hostId, Timestamp startTimestamp, Timestamp endTimestamp);

    /**
     * 查询指定时间范围内的管理的流水情况
     *
     * @param startTimestamp
     * @param endTimestamp
     * @return
     */
    List<IncomeTotalVo> getIncomeTotalList(Timestamp startTimestamp, Timestamp endTimestamp);
    /**
     * 查询指定时间范围内主机流水情况
     *
     * @param startTimestamp
     * @param endTimestamp
     * @return
     */
    List<IncomeTotalVo> getIncomeTotalList(Long hostId, Timestamp startTimestamp, Timestamp endTimestamp);

    List<VpsBuyRecord> findVpsSellRecords(Long hostId, Timestamp startTimestamp, Timestamp endTimestamp);
}
